﻿package com.moonshineproject.plugin.actionscript.as3project.vo 
{
	import com.moonshineproject.utils.TextUtil;
	import com.moonshineproject.utils.Utils;
	
	import flash.filesystem.File;
	public class SWFOutputVO 
	{
		
		public var disabled:Boolean = false;
		
		public var path:File;
		public var frameRate:Number = 24;
		public var swfVersion:uint = 10;
		public var width:int = 100;
		public var height:int = 100;
		
		// TODO What is this? It's present as <movie input="" /> in FD .as3proj
		/** Not sure what this is */
		public var input:String = "";
		
		/** Background color */
		public var background:uint;
		
		
		public function toString():String {
			return "[SWFOutput path='"+path.nativePath+"' frameRate='"+frameRate+"' swfVersion='"+swfVersion+"' width='"+width+"' height='"+height+"' background='#"+backgroundColorHex+"']";
		}
		
		public function get backgroundColorHex():String {
			return TextUtil.padLeft(background.toString(16).toUpperCase(), 6);
		}
		
		public function parse(output:XMLList, folder:File):void {
			var params:XMLList = output.movie;
			
			disabled = Utils.deserializeBoolean(params.@disabled);
			path = folder.resolvePath(Utils.fixSlashes(params.@path));
			frameRate = Number(params.@fps);
			width = int(params.@width);
			height = int(params.@height);
			swfVersion = uint(params.@version);
			background = uint("0x"+String(params.@background).substr(1));
			input = String(params.@input);
		}
		
		/*
			Returns XML representation of this class.
			If root is set you will get relative paths
		*/
		public function toXML(folder:File):XML
		{
			var output:XML = <output/>;
			
			var pathStr:String = path.nativePath;
			if (folder) {
				pathStr = folder.getRelativePath(path);
			}
			
			var outputPairs:Object = {
				'disabled'	: 	Utils.serializeBoolean(disabled),
				'fps'		:	frameRate,
				'path'		:	pathStr,
				'width'		:	width,
				'height'	:	height,
				'version'	:	swfVersion,
				'background':	"#"+backgroundColorHex,
				'input'		:	input
			}
			
			output.appendChild(Utils.serializePairs(outputPairs, <movie/>));
				
			return output;
		}
		
	}
}